"use strict";
Ajax('/api/data', (res) => {
    render(res.data);
});
const render = (data) => {
    // console.log(data)
    const Dowrap = document.querySelector('.wrap');
    Dowrap.innerHTML = data.map((v, i) => {
        return `
               
                <dl id=${v.id}>
                <dt>
                    <img src=${v.img} alt="" />
                </dt>
                <dd>
                    <p><b>${v.title}</b></p>
                </dd>
                </dl>
               `;
    }).join('');
    Bint();
};
const Bint = () => {
    const dls = Array.from(document.querySelectorAll('dl'));
    // console.log(dls)
    dls.forEach(item => {
        item.addEventListener('click', () => {
            location.href = `/detail.html?id=${item.id}`;
        });
    });
};
const seach = document.querySelector('.seach');
const inp = document.querySelector('.inp');
inp === null || inp === void 0 ? void 0 : inp.addEventListener('input', () => {
    let value = inp.value.trim();
    if (value !== '') {
        Ajax(`/api/seach?value=${value}`, (resd) => {
            render(resd.data);
        });
    }
    else {
        Ajax('/api/data', (res) => {
            render(res.data);
        });
    }
});
